package com.unitedats.Project.Servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.unitedats.Project.Entity.PmProject;
import com.unitedats.common.Servlet.BasicServlet;
import com.unitedats.common.util.WebUtil;

public class SearchForProjectProcessServlet extends BasicServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {

		String name = WebUtil.getParamValue(request, "name", null);
		String code = WebUtil.getParamValue(request, "code", null);
		Integer type = WebUtil.getParamValueAsInteger(request, "pType", null);
		Integer status = WebUtil.getParamValueAsInteger(request, "status", null);

		String jpqlStmt = "select p  from PmProject p where p.id!=0 ";
		Map<Integer, Object> map = new HashMap<Integer, Object>();
		int i = 0;
		if (name != null) {
			map.put(++i, "%" + name + "%");
			jpqlStmt += " and p.name like ? ";
		}
		if (code != null) {
			map.put(++i, "%" + code + "%");
			jpqlStmt += " and p.code like ? ";
		}
		if (type != null) {
			map.put(++i, type);
			jpqlStmt += " and p.typeId = ? ";
		}
		if (status != null) {
			map.put(++i, status);
			jpqlStmt += " and p.statusId=? ";
		}

		request.setAttribute("searchResult", dbm.queryJPQL(jpqlStmt, map, PmProject.class));

		basicForward(request, response, "Project/ProjectSearchResult.jsp");
	}

}
